package com.bi.onlineEducation.exception;

/**
 * @Author: chenYuTao
 * @CreateTime: 2021/9/3 10:00
 * @Description:
 **/

public class BusinessHandleException extends RuntimeException {

    private static final long serialVersionUID = -8829404150167813228L;

    private Integer code;
    private String msg;

    public BusinessHandleException(Integer code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public BusinessHandleException(String msg) {
        super(msg);
        this.code = 500;
        this.msg = msg;
    }

    public BusinessHandleException(BusinessHandleCodeEnum exceptionEnum) {
        super(exceptionEnum.getMsg());
        this.code = exceptionEnum.getCode();
        this.msg = exceptionEnum.getMsg();
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }


    public static BusinessHandleException build(Integer code, String msg) {
        return new BusinessHandleException(code, msg);
    }

    public static BusinessHandleException build(BusinessHandleCodeEnum exceptionEnum) {
        return new BusinessHandleException(exceptionEnum.getCode(), exceptionEnum.getMsg());
    }

    public static BusinessHandleException buildBizException(String msg) {
        return new BusinessHandleException(BusinessHandleCodeEnum.DEFAULT_BIZ_EXCEPTION.getCode(), msg);
    }

    @Override
    public synchronized Throwable fillInStackTrace() {
        return this;
    }

    @Override
    public String toString() {
        return "MallBizException{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                '}';
    }
}
